//=---------------------------------------------------------------------=
//
// $Id: AxInit.cpp,v 1.4 2004/04/10 14:21:15 jptrainor Exp $ $Name: V113 $
//
// The contents of this file are subject to the AAF SDK Public
// Source License Agreement (the "License"); You may not use this file
// except in compliance with the License.  The License is available in
// AAFSDKPSL.TXT, or you may obtain a copy of the License from the AAF
// Association or its successor.
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
// the License for the specific language governing rights and limitations
// under the License.
//
// The Original Code of this file is Copyright 1998-2004, Licensor of the
// AAF Association.
//
//=---------------------------------------------------------------------=

#include "AxInit.h"

#include "AxSmartPointer.h"
#include "AxEx.h"
#include "AxHrMap.h"
#include "AxPluginMgr.h"

#include <AAF.h>

#include <stdlib.h>

bool AxInit::once = false;

AxInit::AxInit()
{
  Init( getenv("AX_AAF_COMAPI") );
}


AxInit::AxInit(const char* dllname)
{
  Init( dllname );
}

void AxInit::Init( const char* dllname )
{  
  if ( once ) {
    throw AxEx( L"Multiple AxInit instances not permited." );
  }
  
  // Force the AxHrMap singleton to init so that it doesn't happen
  // the first time an exception is handled.
  AxHrMap::getInstance();
  
  CHECK_HRESULT( AAFLoad( dllname ) );
  
  AxPluginMgr mgr;
  mgr.RegisterSharedPlugins();
  
  once = true;
}

AxInit::~AxInit()
{
	AAFUnload();

	once = false;
}
